<!-- 检查更新 -->
<template>
	<view class="update">
		<u-navbar title="检查更新"></u-navbar>
		<view class="update-content">
			<view class="updateCon">
				<view class="updateConNum " style='border-bottom:1rpx solid rgba(242,242,242,0.95)'>
					<text>当前版本号：</text>
					<text>{{appversion}}</text>
				</view>
				<view class="updateConNum">
					<text>最新版本号：</text>
					<text>{{appversion}}</text>
				</view>
			</view>
			<view class="update-explan">
				<text>版本说明</text>
			</view>
			<view class="updateBtn">
				<button type="primary" @click="isDate">检查更新</button>
			</view>
		</view>
		<u-modal v-model="show" title="发现新版本" :show-confirm-button="false">
			<view class="update-dialog-content">
				<!-- <view class="update-dialog-title">
					检测到新版本
				</view> -->
				<view class="update-dialog-p">
					<view class="update-dialog-p-title">
						新版本更新内容
					</view>
					<view class="update-dialog-p-contetn">
						<view class="" v-for="(item,index) in versionInfo">
							{{item}}
						</view>
					</view>
				</view>
				<view class="update-dialog-ircle">
					<u-line-progress active-color="#2979ff" :percent="progress">
						<view class="u-progress-content">
							<view class="u-progress-dot"></view>
							<text class='u-progress-info'>{{circletext}}</text>
						</view>
					</u-line-progress>
				</view>
			</view>
		</u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fonSizeClass: '',
				progress: 0,
				circletext: "",
				show: false,
				appversion: '1.0.0',
				versionInfo: []
			}
		},
		onLoad() {
			this.isDate()
		},
		methods: {
			isDate() {
				var that = this
				that.versionInfo = []
				plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
					that.appversion = widgetInfo.version
					uni.request({
						url: that.baseUrl + '/set/settb96/settb96ById',
						dataType: 'json',
						method: 'POST',
						data: {
							SETTB96CA01: widgetInfo.version,
							// SETTB96CA01: '1.0.1',  
							SETTB96CA02: 1001
						},
						success: (result) => {
							console.log(result)
							if (result.data.code == 200) {
								if (result.data.data.SETTB96CD02 == 0) {
									that.show = true
									that.versionInfo = result.data.data.SETTB96CA06.split(';')
									var downloadTask = uni.downloadFile({
										url: result.data.data.SETTB96CA05,
										success: (downloadResult) => {
											if (downloadResult.statusCode === 200) {
												console.log(downloadResult.tempFilePath)
												plus.runtime.install(downloadResult
													.tempFilePath, {
														force: true
													},
													function() {
														plus.runtime.restart();
													},
													function(e) {
														that.$refs.uToast.show({
															title: '更新失败，请重试！',
															type: 'default',
															icon: false
														})
														that.show = false
													});
											}
										}

									});
									downloadTask.onProgressUpdate((e) => {
										if (e.progress % 10 == 0) {
											if (that.progress < 100) {
												that.progress += 10
											}
											that.circletext = that.progress + '%'
										}
									})
								}
								else{
									console.log(1)
								}
								// if (result.data.data.SETTB96CD02 == 1 && result.data.data.SETTB96CD03 == 0) {
								// 	that.show = true
								// 	that.doUpData('http://www.feishazoushi.cn/download/customer.apk')
									
								// }
							} else {
								that.show = false
								that.$refs.uToast.show({
									title: '当前已是最新版本！',
									type: 'default',
									icon: false
								})
							}
						}
					});
				});
			}
		}
	}
</script>

<style>
	.updateCon {
		width: 100%;
		background: #fff;
		/* padding:0 20rpx; */
	}

	.updateCon-header {
		background: linear-gradient(90deg, rgba(0, 161, 244, 1), rgba(0, 202, 242, 1));
	}

	.updateConNum {
		width: 93%;
		margin: 0 auto;
		font-weight: 500;
		color: #999999;
		padding: 25rpx 0;
		font-weight: 500;
	}

	.updateConNum text:last-child {
		color: #666666;
	}

	.update-explan {
		background: #fff;
		width: 100%;
		height: 200rpx;
		margin-top: 10rpx;
	}

	.update-explan text {
		color: #999999;
		margin-left: 40rpx;
		margin-top: 30rpx;
		font-weight: 500;
	}

	.updateBtn {
		width: 76%;
		height: 83.34rpx;
		/* background:linear-gradient(90deg,rgba(0,160,241,1),rgba(0,202,242,1)); */

		margin: 0 auto;
	}

	.updateBtn button {
		border: 0;
		outline: 0;
		background: linear-gradient(90deg, rgba(0, 160, 241, 1), rgba(0, 202, 242, 1));
		border-radius: 36rpx;
		margin-top: 72.92rpx;
	}

	.update-content .updateConNum {
		font-size: 25rpx;
	}

	.update-content .update-explan text {
		font-size: 25rpx;
	}

	.update-content6 .updateConNum {
		font-size: 35rpx;
	}

	.update-content6 .update-explan text {
		font-size: 35rpx;
	}

	.update-overlay {
		width: 120rpx;
		height: 120rpx;
	}

	.update-dialog-title {
		line-height: 80rpx;
		text-align: center;
		font-size: 34rpx;
		margin-bottom: 20rpx;
		border-bottom: 1rpx solid #eee;
	}

	.update-dialog-content {
		padding: 20rpx 0;
	}

	.update-dialog-ircle {
		text-align: center;
		padding: 20rpx 20rpx;
	}

	.update-dialog-p {
		margin-bottom: 20rpx;
		padding-left: 40rpx;
		color: #333;
	}

	.update-dialog-p-title {
		margin-bottom: 10rpx;
		padding-left: 15rpx;
		font-size: 26rpx;
	}

	.update-dialog-p-contetn {
		line-height: 60rpx;
		padding-left: 25rpx;
		font-size: 26rpx;
	}
</style>
